package com.ljx.service.impl;

import com.ljx.CourseWebVoOrder;
import com.ljx.UcenterMemberOrder;
import com.ljx.client.CourseWebInterface;
import com.ljx.client.UnCenterInterface;
import com.ljx.pojo.TOrder;
import com.ljx.mapper.TOrderMapper;
import com.ljx.service.TOrderService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ljx.utils.OrderNoUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.web.bind.annotation.PostMapping;

/**
 * <p>
 * 订单 服务实现类
 * </p>
 *
 * @author 李加喜
 * @since 2020-10-02
 */
@Service
public class TOrderServiceImpl extends ServiceImpl<TOrderMapper, TOrder> implements TOrderService {
    @Autowired
    private UnCenterInterface unCenterInterface;
    @Autowired
    private CourseWebInterface courseWebInterface;
    //生成订单  显示订单的详细信息
    @Override
    public String saveOrder(String courseId, String userId) {
        //通过远程调用生成课程信息
        CourseWebVoOrder courseWebVoOrder = courseWebInterface.getCourse(courseId);
        //通过远程调用生成用户的信息
        UcenterMemberOrder memberOrder = unCenterInterface.getMenById(userId);
        //创建Order对象 向Order对象里面设置需要的数据
        TOrder order = new TOrder();
        order.setOrderNo(OrderNoUtil.getOrderNo());//订单号
        order.setCourseId(courseId);//课程的Id
        order.setCourseTitle(courseWebVoOrder.getTitle());//标题
        order.setCourseCover(courseWebVoOrder.getCover());
        order.setTeacherName(courseWebVoOrder.getTeacherName());
        order.setTotalFee(courseWebVoOrder.getPrice());
        order.setMemberId(userId);
        order.setMobile(memberOrder.getMobile()); //得到用户手机号
        order.setNickname(memberOrder.getNickname());//得到用户的昵称
        order.setStatus(0);  //订单状态（0：未支付 1：已支付）
        order.setPayType(1);  //支付类型 ，微信1
        baseMapper.insert(order);
        //返回订单号
        //System.out.println(order.getOrderNo()+"*****");
        return order.getOrderNo();
    }

}
